package main

import (
	"fmt"
	"net/http"
	"webGoDemo/filter"
	"webGoDemo/initConfig"
	"webGoDemo/logs"
	"webGoDemo/router"
	"webGoDemo/swagger"

	"github.com/emicklei/go-restful/v3"
	"github.com/rs/zerolog/log"
)

func main() {

	log.Logger = logs.NewDefaultConsoleLog()

	// 初始化数据库
	initConfig.DBInit()
	//全局过滤
	restful.DefaultContainer.Filter(filter.AuditLogFilter)
	// 初始化路由
	router.AddRecordRouter(restful.DefaultContainer)
	router.AddUserRouter(restful.DefaultContainer)
	router.AddOperateRouter(restful.DefaultContainer)
	swagger.AddWebService(restful.DefaultContainer)

	//开启web监听
	router.AddHealthService(restful.DefaultContainer)
	//logs.Print("finish")
	addr := fmt.Sprintf("%s:%d", "", 9999)
	log.Info().Msg(fmt.Sprintf("http server start to listen, addr port %s", addr))
	err := http.ListenAndServe(addr, nil)
	log.Fatal().Err(err).Msg("http server run over")
	//summerMain.Run()
}
